package vn.easyticket.db.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table( name = "M051_WEB_MEMBERSHIP" )
public class M051_WebMembership
    extends AbstractEntity
{
    private final boolean DEFAULT_IS_ACTIVATED = false;

    private final boolean DEFAULT_IS_CONFIRMED = false;

    private final boolean DEFAULT_IS_DELETED = false;

    private final int DEFAULT_PASSWORD_FAIRLUE_FROM_LAST_SUCCESS = 0;

    @Column( name = "UserId" )
    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private Integer userId;

    @Column( name = "CreateDate", nullable = true )
    @Temporal( TemporalType.TIMESTAMP )
    private Date createDate;

    @Column( name = "ConfirmationToken", length = 128, nullable = true )
    private String confirmationToken;

    @Column( name = "IsConfirmed", nullable = true )
    private Boolean isConfirmed = DEFAULT_IS_CONFIRMED;

    @Column( name = "IsActived", nullable = true )
    private Boolean isActived = DEFAULT_IS_ACTIVATED;

    @Column( name = "IsDeleted", nullable = true )
    private Boolean isDeleted = DEFAULT_IS_DELETED;

    @Column( name = "LastPasswordFailureDate", nullable = true )
    @Temporal( TemporalType.TIMESTAMP )
    private Date lastPasswordFailureDate;

    @Column( name = "PasswordFailuresSinceLastSuccess", nullable = false )
    private int passwordFailuresSinceLastSuccess = DEFAULT_PASSWORD_FAIRLUE_FROM_LAST_SUCCESS;

    @Column( name = "Password", length = 128, nullable = false )
    private String password;

    @Column( name = "PasswordChangedDate", nullable = true )
    @Temporal( TemporalType.TIMESTAMP )
    private Date passwordChangedDate;

    @Column( name = "PasswordSalt", length = 128, nullable = false )
    private String passwordSalt;

    @Column( name = "PasswordVerificationToken", length = 128, nullable = true )
    private String passwordVerificationToken;

    @Column( name = "PasswordVerificationTokenExpirationDate", nullable = true )
    @Temporal( TemporalType.TIMESTAMP )
    private Date passwordVerificationTokenExpirationDate;

    public M051_WebMembership()
    {
    }

    public M051_WebMembership( int userId, Date createDate, int passwordFailuresSinceLastSuccess, String password,
                               String passwordSalt )
    {
        this.userId = userId;
        this.createDate = createDate;
        this.passwordFailuresSinceLastSuccess = passwordFailuresSinceLastSuccess;
        this.password = password;
        this.passwordSalt = passwordSalt;
    }

    public Integer getUserId()
    {
        return userId;
    }

    public void setUserId( Integer userId )
    {
        this.userId = userId;
    }

    public Date getCreateDate()
    {
        return createDate;
    }

    public void setCreateDate( Date createDate )
    {
        this.createDate = createDate;
    }

    public String getConfirmationToken()
    {
        return confirmationToken;
    }

    public void setConfirmationToken( String confirmationToken )
    {
        this.confirmationToken = confirmationToken;
    }

    public Boolean getIsConfirmed()
    {
        return isConfirmed;
    }

    public void setIsConfirmed( Boolean isConfirmed )
    {
        this.isConfirmed = isConfirmed;
    }

    public Boolean getIsActived()
    {
        return isActived;
    }

    public void setIsActived( Boolean isActived )
    {
        this.isActived = isActived;
    }

    public Boolean getIsDeleted()
    {
        return isDeleted;
    }

    public void setIsDeleted( Boolean isDeleted )
    {
        this.isDeleted = isDeleted;
    }

    public Date getLastPasswordFailureDate()
    {
        return lastPasswordFailureDate;
    }

    public void setLastPasswordFailureDate( Date lastPasswordFailureDate )
    {
        this.lastPasswordFailureDate = lastPasswordFailureDate;
    }

    public int getPasswordFailuresSinceLastSuccess()
    {
        return passwordFailuresSinceLastSuccess;
    }

    public void setPasswordFailuresSinceLastSuccess( int passwordFailuresSinceLastSuccess )
    {
        this.passwordFailuresSinceLastSuccess = passwordFailuresSinceLastSuccess;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword( String password )
    {
        this.password = password;
    }

    public Date getPasswordChangedDate()
    {
        return passwordChangedDate;
    }

    public void setPasswordChangedDate( Date passwordChangedDate )
    {
        this.passwordChangedDate = passwordChangedDate;
    }

    public String getPasswordSalt()
    {
        return passwordSalt;
    }

    public void setPasswordSalt( String passwordSalt )
    {
        this.passwordSalt = passwordSalt;
    }

    public String getPasswordVerificationToken()
    {
        return passwordVerificationToken;
    }

    public void setPasswordVerificationToken( String passwordVerificationToken )
    {
        this.passwordVerificationToken = passwordVerificationToken;
    }

    public Date getPasswordVerificationTokenExpirationDate()
    {
        return passwordVerificationTokenExpirationDate;
    }

    public void setPasswordVerificationTokenExpirationDate( Date passwordVerificationTokenExpirationDate )
    {
        this.passwordVerificationTokenExpirationDate = passwordVerificationTokenExpirationDate;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += ( userId != null ? userId.hashCode() : 0 );
        return hash;
    }

    @Override
    public boolean equals( Object object )
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if ( !( object instanceof M051_WebMembership ) )
        {
            return false;
        }
        M051_WebMembership other = (M051_WebMembership) object;
        if ( ( this.userId == null && other.userId != null )
            || ( this.userId != null && !this.userId.equals( other.userId ) ) )
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Easyticket.dbo.[M051_WEB_MEMBERSHIP][ autoNumber=" + userId + " ]";
    }

}
